package com.naizhuai.ui.rank;


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.naizhuai.R;
import com.naizhuai.network.NetWorkObserver;
import com.naizhuai.ui.adapter.ManageDividerItemDecoration;
import com.naizhuai.ui.components.CircleImageView;
import com.naizhuai.ui.entity.User.RankData;
import com.naizhuai.ui.entity.User.UserRank;
import com.naizhuai.ui.user.UserManageDataApiStoreIml;
import com.naizhuai.util.ViewUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


public class TalentListFragment extends BaseRankFragment {
    @BindView(R.id.item_list)
    RecyclerView itemList;
    @BindView(R.id.user_rank)
    TextView userRank;
    @BindView(R.id.user_avatar)
    CircleImageView userAvatar;
    @BindView(R.id.user_name)
    TextView userName;
    @BindView(R.id.teamname)
    TextView teamname;
    @BindView(R.id.user_count)
    TextView userCount;
    private UserManageDataApiStoreIml mDataApiStoreIml;

    public static TalentListFragment newInstance() {
        TalentListFragment fragment = new TalentListFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mDataApiStoreIml == null) {
            mDataApiStoreIml = UserManageDataApiStoreIml.getInstance();
        }
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initData();
    }



    private void initData() {
        showWaitDiaLog();
        loadPersonRank("", "");
    }

    private void loadPersonRank(String key, String dateKey) {
        mDataApiStoreIml.getPerson_Rank(key, dateKey)
                .subscribe(getRankObserver());

    }

    @Override
    public void showSelfData(RankData rankData) {
        userRank.setText(rankData.rank);
        teamname.setText(rankData.departmentName);
        userCount.setText(rankData.totalCount);
        userName.setText(rankData.username);
        ViewUtils.showAvatorOrName(rankData.userThumb, rankData.username, userAvatar);
    }

    @Override
    public void loadFragmentData(String key, String dateKey) {
        getChildFragmentManager().beginTransaction()
                .replace(R.id.item_detail_container, TalentDataFragment.newInstance(key, dateKey))
                .commit();
    }


    @Override
    protected int getLayoutResID() {
        return R.layout.fragment_talent_list;
    }


    @Override
    public void loadRankData(String key, String datekey) {
           loadPersonRank("", datekey);
    }
}
